package io.jee.runshan.domain;

import java.math.BigDecimal;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@Table(name = "runshan_car")
@JsonIgnoreProperties(value = { "id" })
public class ShoppingCar {
	private Integer id;
	private BigDecimal fullAmount = new BigDecimal(0); // 总金额
	private BigDecimal preAmount = new BigDecimal(0); // 预付款
	private Integer productCount = 0; // 商品数量
	private String wxOpenid;
	
	public void addPrudoct(ShoppingCarProduct carProduct) {
		this.productCount = this.productCount + 1;
		this.fullAmount = this.fullAmount.add(carProduct.getProduct().getSalesPrice().multiply(new BigDecimal(carProduct.getBuyCount())));
		this.preAmount = this.fullAmount.multiply(new BigDecimal(0.2));
		this.fullAmount.setScale(2, BigDecimal.ROUND_DOWN);
		this.preAmount.setScale(2, BigDecimal.ROUND_DOWN);
	}
	
	public void clearProduct() {
		this.productCount = 0;
		this.fullAmount = new BigDecimal(0);
		this.preAmount = new BigDecimal(0);
	}

	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getWxOpenid() {
		return wxOpenid;
	}

	public void setWxOpenid(String wxOpenid) {
		this.wxOpenid = wxOpenid;
	}

	public BigDecimal getFullAmount() {
		return fullAmount;
	}

	public void setFullAmount(BigDecimal fullAmount) {
		this.fullAmount = fullAmount;
	}

	public BigDecimal getPreAmount() {
		return preAmount;
	}

	public void setPreAmount(BigDecimal preAmount) {
		this.preAmount = preAmount;
	}

	public Integer getProductCount() {
		return productCount;
	}

	public void setProductCount(Integer productCount) {
		this.productCount = productCount;
	}

}
